/**
 * 
 */
package org.cuatrovientos.erp.dao;

import java.util.List;

import org.cuatrovientos.erp.model.IssueType;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Daniel Lacasta
 */
public class IssueTypeDAO implements GenericInterfaceDAO {

	@Autowired
	 private SessionFactory sessionFactory;
	
	/**
	 * Get list's <IssueType>
	 */
	@Override
	public List<IssueType> selectAll() {

	    List<IssueType> issuetypes = getSession().createQuery("from issuetype").list();
	    return issuetypes;
	}

	/**
	 * Get an <IssueType>
	 */
	@Override
	public IssueType selectById(int id) {
		IssueType issuetype = (IssueType) getSession().get(IssueType.class, id);
	    return issuetype;
	}

	/**
	 * delete an <IssueType>
	 */
	@Override
	public void delete(int id) {
		IssueType issuetype = selectById(id);
		getSession().delete(issuetype);
		
	}

	/**
	 * Insert an <IssueType>
	 */
	@Override
	public void insert(Object newIssueType) {
		 Integer id = (Integer) getSession().save(newIssueType);
		    ((IssueType) newIssueType).setId(id);  
		
	}

	/**
	 * update an <IssueType>
	 */
	@Override
	public void update(Object issuetype) {
		getSession().merge(issuetype);
		
	}

	/**
	 * Get a session.
	 */
	@Override
	public Session getSession() {
		 return sessionFactory.getCurrentSession();
	}

	

}
